package com.example.teatea.dao;

import com.example.teatea.project.Staff;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.*;
import java.util.Properties;

public class AddStaff {
    public boolean addStaff(Staff staff){
        Connection conn=null;
        ResultSet res=null;
        try {
            Properties info=new Properties();
            info.load(new FileInputStream("src\\main\\resources\\com\\example\\teatea\\sql.properties"));
            String user=info.getProperty("user");
            String password=info.getProperty("password");
            String Driver=info.getProperty("Driver");
            String url=info.getProperty("url");
            Class.forName(Driver);
            conn= DriverManager.getConnection(url,user,password);
            String sql="insert into staff(sName,sSex,sPhone,sType,sPsw,sState)values(?,?,?,?,?,?)";
            PreparedStatement presta = conn.prepareStatement(sql);
            presta.setString(1, staff.getsName());
            presta.setString(2, staff.getsSex());
            presta.setString(3,staff.getsPhone());
            presta.setString(4,staff.getsType());
            presta.setString(5,staff.getsPsw());
            presta.setInt(6,staff.getsState());
            int f=0;
            f=presta.executeUpdate();
            if(f!=0){
                return true;
            }else{
                return false;
            }
        }catch(SQLException e){
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return false;
    }
}
